OPC Studio User's Guide and Reference
Browsing for OPC A&E Servers
Client and Subscriber Development > Development Models > Imperative Programming Model > Imperative Programming Model for OPC Classic A&E > Browsing for Information (OPC A&E) > Browsing for OPC A&E Servers

If you want to retrieve a list of OPC Alarms and Events servers registered on a local or remote computer, call the BrowseServers method, passing it the name or address of the remote machine (use empty string for local computer).

You will receive back a ServerElementCollection object. If you want to connect to this OPC server later in your code by calling other methods, use the built-in conversion of ServerElement to String, and pass the resulting string as a serverClass argument either directly to the method call, or to a constructor of ServerDescriptor object.

Each ServerElement contains information gathered about one OPC server found on the specified machine, including things like the server’s CLSID, ProgID, vendor name, and readable description.

.NET

// This example shows how to obtain all ProgIDs of all OPC Alarms and Events servers on the local machine.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

using System;
using System.Diagnostics;
using OpcLabs.EasyOpc;
using OpcLabs.EasyOpc.AlarmsAndEvents;
using OpcLabs.EasyOpc.OperationModel;

namespace DocExamples.AlarmsAndEvents._EasyAEClient
{
    class BrowseServers 
    { 
        public static void Main1()
        {
            // Instantiate the client object.
            var client = new EasyAEClient();

            ServerElementCollection serverElements;
            try
            {
                serverElements = client.BrowseServers("");
            }
            catch (OpcException opcException)
            {
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message);
                return;
            }

            foreach (ServerElement serverElement in serverElements)
            {
                Debug.Assert(serverElement != null);
                Console.WriteLine("serverElements[\"{0}\"].ProgId: {1}", serverElement.Clsid, serverElement.ProgId);
            }
        }
    } 
}
' This example shows how to obtain all ProgIDs of all OPC Alarms and Events servers on the local machine.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Imports OpcLabs.EasyOpc
Imports OpcLabs.EasyOpc.AlarmsAndEvents
Imports OpcLabs.EasyOpc.OperationModel

Namespace AlarmsAndEvents._EasyAEClient

    Friend Class BrowseServers
        Public Shared Sub Main1()
            Dim client = New EasyAEClient()

            Dim serverElements As ServerElementCollection
            Try
                serverElements = client.BrowseServers("")
            Catch opcException As OpcException
                Console.WriteLine("*** Failure: {0}", opcException.GetBaseException().Message)
                Exit Sub
            End Try

            For Each serverElement As ServerElement In serverElements
                Debug.Assert(serverElement IsNot Nothing)
                Console.WriteLine("serverElements[""{0}""].ProgId: {1}", serverElement.Clsid, serverElement.ProgId)
            Next serverElement
        End Sub
    End Class

End Namespace

COM

Rem This example shows how to obtain all ProgIDs of all OPC Alarms and Events servers on the local machine.
Rem
Rem Find all latest examples here : https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .

Option Explicit

Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.AlarmsAndEvents.EasyAEClient")
On Error Resume Next
Dim ServerElements: Set ServerElements = Client.BrowseServers("")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

Dim ServerElement: For Each ServerElement In ServerElements
    WScript.Echo "ServerElements(""" & ServerElement.UrlString & """).ProgId: " & ServerElement.ProgId
Next

 

 

See Also